<template>
  <div id="header">
    <div class="header">
      <div class="header-left">
        <img src="../assets/logo.png" alt="">
      </div>
      <div class="header-center">
        <div class="header-center-item" v-for='(item,index) in headerCenterItem' :key='index' :class="{
        'active-one': index == centerItemCurrent || index == centerItemActive
          }" @mouseover='centerItemActive = index' @mouseout='centerItemActive = centerItemCurrent'>{{item}}
        <div class="active-action" v-if = 'centerItemCurrent == index'></div>
        </div>
      </div>
      <div class="header-right">
        <input type="text" placeholder="音乐/视频/电台/用户">
        <img src="../assets/sousuo.png" alt="" class="header-serch">
        <button class="search-button" 
        @mouseover ='isSearchActive = true'  @mouseout='isSearchActive = false'
        :class="{'search-active': isSearchActive == true}">搜索</button>
        <a href="" class="login">登录</a>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'Header',
    data() {
      return {
        headerCenterItem: ['发现音乐', '我的音乐', '朋友', '商城', '音乐人', '下载客户端'],
        centerItemCurrent: Number,//当前页面默认active
        centerItemActive: Number,//根据事件确认的active
        isSearchActive:false,
      }
    },
    created() {
      if (this.$route.path == '/') {
        this.centerItemCurrent = 0
        this.centerItemActive = this.centerItemCurrent
      }
    }
  }
</script>

<style>
  #header {
    height: 70px;
    width: 100%;
    background: rgb(36, 36, 36)
  }

  .header {
    width: 1260px;
    height: 70px;
    margin: auto;
  }

  .header-left {
    float: left;
    height: 100%;
    width: 230px;
    position: relative;
  }

  .header-left img {
    position: absolute;
    right: 0;
    top: 5px;
    width: 200px;
    height: 60px;
  }

  .header-center {
    height: 100%;
    width: 560px;
    float: left;
    display: flex;
  }

  .header-center-item {
    text-align: center;
    flex: 1;
    height: 100%;
    line-height: 70px;
    color: #ccc;
    font-size: 14px;
    cursor: pointer;
    position: relative;
  }

  .active-one {
    background: black !important;
    color: white !important;
  }

  .header-right {
    float: left;
    width: 470px;
    height: 100%;
    position: relative;
  }

  .header-right input {
    border: 0px;
    border-radius: 30px;
    outline: none;
    height: 30px;
    margin-top: 20px;
    margin-left: 50px;
    text-indent: 30px;
    font-size: 8px;
  }

  .header-serch {
    width: 20px;
    height: 20px;
    position: absolute;
    top: 26px;
    left: 60px;
  }

  .search-button {
    background: rgb(36, 36, 36);
    color: #ccc;
    width: 60px;
    height: 30px;
    border-radius: 30px;
    border: 1px solid #ccc;
    margin-left: 20px;
    cursor: pointer;
    outline: none
  }

  .search-active{
    color: white !important;
    border-color: white !important
  }

  .login {
    color: #ccc;
    font-size: 12px;
    text-decoration: none;
    margin-left: 30px;
  }

  .active-action {
    background: none;
    width: 0;
    height: 0;
    border-bottom: 7px solid rgb(194, 12, 12);
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    position: absolute;
    bottom: 0;
    left: 41px;
  }

  .header-right a:hover{
    text-decoration: underline !important;
    color: white !important
  }
</style>